import requests
import json

url = 'http://localhost:8001/api/openapi.json'
print(f"尝试获取OpenAPI文档: {url}")

try:
    response = requests.get(url, timeout=10)
    print(f"状态码: {response.status_code}")
    
    if response.status_code == 200:
        # 保存OpenAPI文档到文件
        with open('openapi.json', 'w', encoding='utf-8') as f:
            f.write(response.text)
        print("OpenAPI文档已保存到openapi.json")
        
        # 解析并显示部分内容
        data = response.json()
        print("\n可用的API路径:")
        if 'paths' in data:
            for path in data['paths']:
                print(f"  - {path}")
    else:
        print(f"请求失败: {response.text}")
except Exception as e:
    print(f"发生错误: {e}")